//https://www.nowcoder.com/practice/253d2c59ec3e4bc68da16833f79a38e4?tpId=13&tqId=23449&ru=/exam/oj/ta&qru=/ta/coding-interviews/question-ranking&sourceUrl=%2Fexam%2Foj%2Fta%3Fpage%3D1%26tpId%3D13%26type%3D13
#include <unordered_set>
/*
struct ListNode {
    int val;
    struct ListNode *next;
    ListNode(int x) :
        val(x), next(NULL) {
    }
};
*/
#include <unordered_map>
class Solution {
public:
    ListNode* EntryNodeOfLoop(ListNode* pHead) {

        // while(!pHead)
        // {
        //     return nullptr;
        // }

        // if(pHead->next == pHead)
        // {
        //     return pHead;
        // }

        unordered_set<ListNode*> st;
        while(pHead)
        {
            if(st.count(pHead))
            {
                return pHead;
            }
            
            st.insert(pHead);
            pHead = pHead->next;
        }
        return nullptr;


    }
};